package com.diana.config;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * RocketMq事务消息监听实现
 */
@Component
public class TransactionListenerImpl implements TransactionListener {

    private static final Logger log = LoggerFactory.getLogger(TransactionListenerImpl.class);

    /**
     * 执行本地事务
     * @param message
     * @param o
     * @return
     */
    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object o) {
        log.info("进入事务消息监听:{}",message);
        return LocalTransactionState.COMMIT_MESSAGE;
    }

    /**
     * 验证本地事务是否执行
     * @param messageExt
     * @return
     */
    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        return null;
    }
}
